From 793134c2c4bd8aa191679ea40b17cb03a5041227 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 16 Aug 2014 11:20:47 -0700 Subject: [PATCH] Add submodule test from #381 --- tests/test_cargo_compile_git_deps.rs | 94 +++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index a8a7223ab..241dc2ba9 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -4,7 +4,7 @@ use std::time::Duration; use support::{ProjectBuilder, ResultTest, project, execs, main_file, paths}; use support::{cargo_dir, path2url}; -use support::{COMPILING, FRESH, UPDATING}; +use support::{COMPILING, FRESH, UPDATING, RUNNING}; use support::paths::PathExt; use hamcrest::{assert_that,existing_file}; use cargo; @@ -860,3 +860,95 @@ test!(stale_cached_version { ", updating = UPDATING, compiling = COMPILING, bar = bar.url(), foo = foo.url()))); assert_that(foo.process(foo.bin("foo")), execs().with_status(0)); }) + +test!(dep_with_changed_submodule { + let project = project("foo"); + let git_project = git_repo("dep1", |project| { + project + .file("Cargo.toml", r#" + [package] + name = "dep1" + version = "0.5.0" + authors = ["carlhuda@example.com"] + "#) + }).assert(); + + let git_project2 = git_repo("dep2", |project| { + project + .file("lib.rs", "pub fn dep() -> &'static str { \"project2\" }") + }).assert(); + + let git_project3 = git_repo("dep3", |project| { + project + .file("lib.rs", "pub fn dep() -> &'static str { \"project3\" }") + }).assert(); + + git_project.process("git").args(["submodule", "add"]) + .arg(git_project2.root()).arg("src").exec_with_output().assert(); + git_project.process("git").args(["add", "."]).exec_with_output().assert(); + git_project.process("git").args(["commit", "-m", "test"]).exec_with_output() + .assert(); + + let project = project + .file("Cargo.toml", format!(r#" + [project] + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + [dependencies.dep1] + git = '{}' + "#, git_project.url())) + .file("src/main.rs", " + extern crate dep1; + pub fn main() { println!(\"{}\", dep1::dep()) } + "); + + assert_that(project.cargo_process("cargo-run"), execs() + .with_stdout(format!("{} git repository `[..]`\n\ + {} dep1 v0.5.0 ([..])\n\ + {} foo v0.5.0 ([..])\n\ + {} `target/foo`\n\ + project2\ + ", + UPDATING, + COMPILING, + COMPILING, + RUNNING)) + .with_stderr("") + .with_status(0)); + + let mut file = File::create(&git_project.root().join(".gitmodules")); + file.write_str(format!("[submodule \"src\"]\n\tpath = src\n\turl={}", + git_project3.root().display()).as_slice()); + + git_project.process("git").args(["submodule", "sync"]).exec_with_output().assert(); + git_project.process("git").args(["fetch"]).cwd(git_project.root().join("src")) + .exec_with_output().assert(); + git_project.process("git").args(["reset", "--hard", "origin/master"]) + .cwd(git_project.root().join("src")).exec_with_output().assert(); + git_project.process("git").args(["add", "."]).exec_with_output().assert(); + git_project.process("git").args(["commit", "-m", "test"]).exec_with_output() + .assert(); + + timer::sleep(Duration::milliseconds(1000)); + // Update the dependency and carry on! + assert_that(project.process(cargo_dir().join("cargo-update")), execs() + .with_stderr("") + .with_stdout(format!("{} git repository `{}`", + UPDATING, + git_project.url()))); + + assert_that(project.cargo_process("cargo-run"), execs() + .with_stdout(format!("{} git repository `[..]`\n\ + {} dep1 v0.5.0 ([..])\n\ + {} foo v0.5.0 ([..])\n\ + {} `target/foo`\n\ + project3\ + ", + UPDATING, + COMPILING, + COMPILING, + RUNNING)) + .with_stderr("") + .with_status(0)); +}) -- 2.30.2